<?php 
# $Id$
require_once(APP_LIB_DIR . 'Sajax.php');
require_once('utils.inc.php');
require_once('header.php'); 
$pid = $template['pid'];
$all = $template['all'];
$list = $template['list'];
$options = $template['options'];
$detail = $template['detail'];

$total = 0;
foreach ($options as $d):
$total += $d['votes'];
endforeach;
?>
 <div id="panel">
          <table class="adminlist" width="100%">
            <tr>
              <td>
                <form id="form1" class="wufo" action="" method="post">
                  <ul>
                    <li>
                      <span>
                        <label class="desc">Select Poll :</label>
                      </span>
                      <span>
                        <select class="field select" style="width:10em" name="poll_id">
                        <? foreach($all as $one):?>
                        <option value="<?=$one['id']?>"><?=$one['name']?></option>
                        <? endforeach ?>
                        </select>
                      </span>
                      <span>
                        <input id="saveForm" class="btTxt" type="submit" value="View" />
                      </span>
                    </li>
                  </ul>
                </form>
              </td>
            </tr>
          </table>
        </div>

        <br />
        <center><img src="?module=<?=DEFAULT_MODULE?>&action=PollResult&poll_id=<?=$pid?>&cb=<?=date("His")?>" /></center>
        <br />
    <div class="main">
        <table class="adminheading">
            <tr>
                <th class="cpanel" rowspan="2" nowrap>Poll Result&nbsp;<font size="1px" color="#CCCCCC">[<?=strtoupper($auth['privilege'])?>]</font></th>
            </tr>
        </table>
    </div>

    <div>
<ul>
<?php foreach($options as $d): 
        $percent = ($total) ? round(($d['votes']/$total)*100) : 0;
?>

<li> <a href="#" onClick="t_details('<?=$d['id']?>')"><?=$d['name']?> (<?=$d['code']?>)</a> - <?=$d['description']?> = <b><?= $percent ?>%</b> 
<? endforeach; ?>
</ul>
    </div>
<!--
       <table class='adminlist'>
           <thead>
                <tr>
                    <th>Name</th>
                    <th>Description</th>
                    <th>Code</th>
                    <th>Unique Votes</th>
                    <th>All Votes</th>
                </tr>
            </thead>
                <? if ($list) foreach($list as $idx  => $l): 
                     $cls = ($idx%2 == 0) ? "" : "odd";
                ?>
                <tr class="<?=$cls?>">
                    <td><?=$l['name']?></td>
                    <td><?=$l['description']?></td>
                    <td align="center"><?=$l['code']?></td>
                    <td align="center"><?=$l['distinct_vote']?></td>
                    <td align="center"><?=$l['total_sms']?></td>
                </tr>
                <? endforeach ?>
            <tbody>
            </tbody>

        </table>
-->
<script>
    function t_details(id){
        URL = "?module=<?=DEFAULT_MODULE?>&action=VoterList&poll_result_id=" + id
        npop(URL)
    }
</script>
<?php require_once('footer.php'); ?>
